package net.techwatch.contacts.client;

import net.techwatch.contacts.shared.Contact;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ContactForm extends DialogBox {

	private static final ContactFormUiBinder uiBinder = GWT.create(ContactFormUiBinder.class);
	
	interface ContactFormUiBinder extends UiBinder<Widget, ContactForm> {}
	
	private Controller controller;
	
	@UiField
	TextBox lastName;
	
	@UiField
	TextBox firstName;
	
	@UiField
	TextBox emailAddress;
	
	@UiField
	Button okButton;
	
	@UiField
	Button cancelButton;
	
	public ContactForm(Controller controller) {
		this.controller = controller;
		this.setText("Add Contact");
		this.setModal(true);
		this.setGlassEnabled(true);
		
		this.add(uiBinder.createAndBindUi(this));
	}
	
	@UiHandler("cancelButton")
	void onCancel(ClickEvent event) {
		hide();
	}
	
	@UiHandler("okButton")
	void onOk(ClickEvent event) {
		Contact c = new Contact(firstName.getText(), lastName.getText(), emailAddress.getText());
		controller.addContacts(c);
		hide();
	}
}
